package com.etc.service;

import com.etc.common.ResultBody;
import com.etc.common.ResultStatusEnums;
import com.etc.entity.User;
import com.etc.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author kalista
 * @Description
 * @Date 2021/2/26  9:22
 **/
@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;


    public List<User> findAll(){
        return  userMapper.selectList(null);
    }


    public ResultBody deleteById(Integer id){
        int reslut = userMapper.deleteById(id);
        if (reslut > 0){
            return ResultBody.ok();
        }
        return ResultBody.error(ResultStatusEnums.USERNAME_IS_NULL);
    }
    public ResultBody save(User user){
        int reslut = userMapper.insert(user);
        if (reslut > 0){
            return ResultBody.ok();
        }
        return ResultBody.error(ResultStatusEnums.USERNAME_IS_NULL);
    }

    public User findById(Integer id){
        User user = userMapper.selectById(id);
        return user;

    }


    public Integer update(User user){
        int update = userMapper.update(user);
        return update;
    }

}
